<?php

namespace App\Http\Model;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;

/**
 * 老用户回归送礼物表
 */
class RecalledSendProp extends Base
{
    public $table = 'recalled_send_prop';


    public function __construct(array $attributes = [])
    {
        parent::__construct($this->table, $attributes);
    }

    /**
     * 读取当前手机号的送出状态
     * @return int 1已送出过，0还未送出，-1没有找到手机号
     * */
    public function getStatusByPhone($type, $phone)
    {
        $result = DB::table($this->table)
            ->select(['status'])
            ->where('phone', $phone)
            ->where('type', $type)
            ->first();

        if ($result === null) {
            return -1;
        }

        return intval($result->status);
    }

    /**
     * 更新送出记录
     * */
    public function updateStatus($type, $phone)
    {
        return DB::table($this->table)
            ->where('phone', $phone)
            ->where('type', $type)
            ->update(['status' => 1]);
    }

}